package com.lianxian.xindong.login.mvp.ui.activity;

import android.app.Dialog;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

import com.hxb.library.base.BaseActivity;
import com.hxb.library.di.component.AppComponent;
import com.hxb.library.utils.HxbUtils;
import com.lianxian.xindong.commonres.weight.ClearEditText;
import com.lianxian.xindong.commonsdk.utils.ImmersionBarUtil;
import com.lianxian.xindong.login.R;
import com.lianxian.xindong.login.R2;
import com.lianxian.xindong.login.di.component.DaggerLoginOtherComponent;
import com.lianxian.xindong.login.mvp.contract.LoginOtherContract;
import com.lianxian.xindong.login.mvp.presenter.LoginOtherPresenter;

import javax.inject.Inject;

import butterknife.BindView;
import butterknife.OnClick;

import static com.hxb.library.utils.Preconditions.checkNotNull;


/**
 * @作者：hexingbo
 * @时间：06/30/2023
 * @描述：
 */
public class LoginOtherActivity extends BaseActivity<LoginOtherPresenter> implements LoginOtherContract.View {

    @Inject
    Dialog mDialog;

    @BindView(R2.id.et_account_number)
    ClearEditText etAccountNumber;
    @BindView(R2.id.et_account_password)
    ClearEditText etAccountPassword;
    @BindView(R2.id.btn_login)
    Button btnLogin;
    @BindView(R2.id.btn_register)
    Button btnRegister;
    @BindView(R2.id.iv_login_type_other)
    ImageView ivLoginTypeOther;
    @BindView(R2.id.cb_agreement)
    CheckBox cbAgreement;
    @BindView(R2.id.tv_agreement_service)
    TextView tvAgreementService;
    @BindView(R2.id.tv_agreement_privacy)
    TextView tvAgreementPrivacy;

    @Override
    public void setupActivityComponent(@NonNull AppComponent appComponent) {
        DaggerLoginOtherComponent //如找不到该类,请编译一下项目
                .builder()
                .appComponent(appComponent)
                .view(this)
                .build()
                .inject(this);
    }

    @Override
    public int initView(@Nullable Bundle savedInstanceState) {
        return R.layout.activity_login_other; //如果你不需要框架帮你设置 setContentView(id) 需要自行设置,请返回 0
    }

    @Override
    public void initData(@Nullable Bundle savedInstanceState) {
        ImmersionBarUtil.setImmersionBar(this,true);
    }

    @Override
    public void showLoading() {
        mDialog.show();
    }

    @Override
    public void hideLoading() {
        mDialog.dismiss();
    }

    @Override
    public void showMessage(@NonNull String message) {
        checkNotNull(message);
        HxbUtils.snackbarText(message);
    }

    @Override
    public void launchActivity(@NonNull Intent intent) {
        checkNotNull(intent);
        HxbUtils.startActivity(intent);
    }

    @Override
    public void killMyself() {
        mDialog = null;
        finish();
    }

    /**
     * 登录，注册，其他方式登录切换点击事件处理
     *
     * @param view
     */
    @OnClick({R2.id.btn_login, R2.id.btn_register, R2.id.iv_login_type_other})
    public void onBtnViewClicked(View view) {
        if (view.getId() == R.id.btn_login) {
            //登录
            mPresenter.submitLoginData(etAccountNumber.getText().toString(), etAccountPassword.getText().toString());
        } else if (view.getId() == R.id.btn_register) {
            //注册
            mPresenter.goRegisterInfo();
        } else if (view.getId() == R.id.iv_login_type_other) {
            //切换登录方式
            mPresenter.changeLoginType();
        }
    }

    /**
     * 协议点击事件处理
     *
     * @param view
     */
    @OnClick({R2.id.cb_agreement, R2.id.tv_agreement_service, R2.id.tv_agreement_privacy})
    public void onAgreementViewClicked(View view) {
        if (view.getId() == R.id.cb_agreement) {
            //勾选协议
            mPresenter.checkAgreement(cbAgreement.isChecked());
        } else if (view.getId() == R.id.tv_agreement_service) {
            //使用服务协议
        } else if (view.getId() == R.id.tv_agreement_privacy) {
            //隐私政策
        }
    }

    @Override
    public Context getContext() {
        return this;
    }
}
